<?php
namespace app\index\Controller;
use think\Db;
use think\Session;
use think\Controller;
use app\index\model\Userinfomodel;
use think\Request;

class Userinfo extends Controller{

    public function index(){
        $request = Request::instance();
        $uid = Session::get('uid');
        $name = $request->param('name');
        $telephone = $request->param('telephone');
        $email = $request->param('email');
        $city = $request->param('city');
        $headerUrl = $request->param('headerUrl');
        $callback=  $request->param("callback");

        $data = array(
            'name' => $name,
            'telephone' => $telephone,
            'email' => $email,
            'city' => $city,
            'uid' => $uid,
            'headerUrl' => $headerUrl

        );
        Session::set('data', $data);

       if(Session::get('data')){

           echo $callback."(1)";
       }else{
           echo $callback."(2)";
       }
    }

    public function a(){
        $request = Request::instance();
        $callback=  $request->param("callback");
        $uid = Session::get('uid');
        $school = $request->param('school');
        $major = $request->param('major');
        $wrokeday = $request->param('wrokeday');
        $studyName = $request->param('studyName');


        $data2 = array(
            'school' => $school,
            'major' => $major,
            'studyName' => $studyName,
            'wrokeday' => $wrokeday,
            'uid' => $uid,
        );
        Session::set('data2',$data2);
        if(Session::get('data2')){
            echo $callback."(1)";
        }else{
            echo $callback."(2)";
        }


    }

    public function c(){
        $request = Request::instance();
        $uid = Session::get('uid');
        $callback = $request->param('callback');
        $startTime = $request->param('startTime');
        $endTime = $request->param('endTime');
        $companyname = $request->param('companyname');
        $position = $request->param('position');
        $description = $request->param('description');

        $data3 = array(
            'startTime' => $startTime,
            'endTime' => $endTime,
            'companyname' => $companyname,
            'position' => $position,
            'description' => $description,
            'uid' => $uid,
        );
        Session::set('data3',$data3);

        if(Session::get('data3')){
            echo $callback."(1)";
        }else{
            echo $callback."(2)";
        }
    }

    public function b(){
        $request = Request::instance();
        $callback = $request->param('callback');
        $pingjia = $request->param('pingjia',"");



        $data = Session::get('data');
        $data2 = Session::get('data2');
        $data3 = Session::get('data3');
        $data3["pinjia"]=$pingjia;


        $row = new Userinfomodel();
        $result = $row->register($data, $data2, $data3);




        if($result){
            return $callback."(1)";
        }else{
            return $callback."(2)";
        }
    }


    public function resume(){
        $request= Request::instance();
        $callback = $request->get('callback');
        $id['rs_puser_info.uid']= Session::get('uid');
        $model = new Userinfomodel();
        $res= $model->sel($id);

            if($res){
                echo $callback."(".json_encode($res).")";}




    }
    public function xg(){


        $request= Request::instance();
        $callback = $request->get('callback');
        $id['rs_puser_info.uid']= Session::get('uid');
        $companyname= $request->get('companyname');
        $description= $request->get('description');
        $position= $request->get('position');
        $startTime= $request->get('startTime');
        $endTime= $request->get('endTime');
        $model = new Userinfomodel();
        $data=array('companyname'=>$companyname,'description'=>$description,'position'=>$position,
            'startTime'=>$startTime,'endTime'=>$endTime);

        $re=$model->xg1($id['rs_puser_info.uid'],$data);
        if($re){
            return $callback."(0)";
        }else{
            return $callback."(1)";
        }

    }
    public function jy(){
        $request= Request::instance();
        $callback = $request->get('callback');
        $id['rs_puser_info.uid']= Session::get('uid');
        $school= $request->get('school');
        $major= $request->get('major');
        $studyName= $request->get('studyName');
        $model = new Userinfomodel();

        $data=array('school'=>$school,'major'=>$major,'studyName'=>$studyName);

        $re=$model->jy1($id['rs_puser_info.uid'],$data);

        if($re){
            return $callback."(0)";
        }else{
            return $callback."(1)";
        }
    }
    public function pj(){
        $request= Request::instance();
        $callback = $request->get('callback');
        $id['rs_puser_info.uid']= Session::get('uid');
        $pinjia= $request->get('pinjia');
        $model = new Userinfomodel();
        $data=array('pinjia'=>$pinjia);
        $re=$model->xg1($id['rs_puser_info.uid'],$data);
        if($re){
            return $callback."(0)";
        }else{
            return $callback."(1)";
        }
    }

    public  function uploadFile(){
        if ((($_FILES["file"]["type"] == "image/gif")
                || ($_FILES["file"]["type"] == "image/jpeg")
                || ($_FILES["file"]["type"] == "image/pjpeg"))
            && ($_FILES["file"]["size"] < 2000000))
        {
            if ($_FILES["file"]["error"] > 0)
            {
                $data = array(
                    'error' =>  $_FILES["file"]["error"],
                    'msg'   => 'some error happend',
                    'imgurl' => null,
                );
                $url = 'http://www.home.com/uploadImg.php';
                $data = json_encode($data);
                header('Location:' .$url . '?data=' . $data);
            }
            else
            {
                if (file_exists("./static/upload/" . $_FILES["file"]["name"]))
                {
                    $data = array(
                        'error' =>  null,
                        'msg'   => 'file already exists',
                        'imgurl' => null,
                    );
                    $url = 'http://www.home.com/uploadImg.php';
                    $data = json_encode($data);
                    header('Location:' .$url . '?data=' . $data);
                }
                else
                {
                        $imgName= explode(".",$_FILES["file"]["name"]);
//                    ????????????????UPload????????��??????��?????
                    $imginfo=time().".".$imgName[1];
                    $img['headUrl']=$imginfo;
                    move_uploaded_file($_FILES["file"]["tmp_name"], "./static/upload/" .$imginfo);




                        $data = array(
                            'error' =>  null,
                            'msg'   => 'upload success',
                            'imgurl' => 'http://www.admin.com/static/upload/'. $imginfo,
                        );
                        $url = 'http://www.home.com/uploadImg.php';
                        $data = json_encode($data);
                        header('Location:' .$url . '?data=' . $data);
                        exit;
                }

            }
        }
        else
        {
            $data = array(
                'error' =>  null,
                'msg'   => 'file type not allowed',
                'imgurl' =>null,
            );
            $url = 'http://www.home.com/uploadImg.php';
            $data = json_encode($data);
            header('Location:' .$url . '?data=' . $data);
        }
    }

//   ???????????????��;
    public  function Sendresume(){
        $request= Request::instance();
        $callback = $request->get('callback');
        $data['companyId'] = $request->param('companyId');
        $data['placeId'] = $request->param('id');
        $data['input'] = $request->param('input',"");
        $data['uid']= Session::get('uid');
//        ??????????????��???????;
        $request=   Db::name("Sendresume")->insert($data);

        if($request){
            echo $callback."(1)";
        }else{
            echo $callback."(0)";
        }


    }
//    获得登录用户注册名字;
    public  function  getuserinfoname(){
        $request= Request::instance();
        $callback = $request->get('callback');
        $data['uid']= Session::get('uid');
      $name=Db::name("puser_info")->where($data)->find();
        if($name){
       echo      $callback."(".json_encode($name['name']).")";
        }else{
        echo     $callback."(0)";
        }
    }
// 个人投递的简历数量；（提示框）
 public  function getSendresumecunt(){
     $request= Request::instance();
     $callback = $request->get('callback');
     $data['uid']= Session::get('uid');
     $data['delectInfo']=0;
     $count= Db::name("sendresume")->where($data)->count();
     if($count){
         echo $callback."($count)";
     }else{
         echo $callback.(0);
     }

 }
// 个人投递的简历投递了的未处理数量；（提示框）

public function  getSendresumenumber(){
    $request= Request::instance();
    $callback = $request->get('callback');
    $data['uid']= Session::get('uid');
    $data['status']=0;
    $data['delectInfo']=0;
    $count= Db::name("sendresume")->where($data)->count();
    if($count){
        echo $callback."($count)";
    }else{
        echo $callback.(0);
    }
}
    // 个人投递的简历投递了的通过的数量；（提示框）

    public function  getSendresumepass(){
        $request= Request::instance();
        $callback = $request->get('callback');
        $data['uid']= Session::get('uid');
        $data['status']=2;
        $data['delectInfo']=0;
        $count= Db::name("sendresume")->where($data)->count();
        if($count){
            echo $callback."($count)";
        }else{
            echo $callback.(0);
        }
    }

    // 个人投递的简历投递了的拒绝的数量；（提示框）

    public function  getSendresumeNo(){
        $request= Request::instance();
        $callback = $request->get('callback');
        $data['uid']= Session::get('uid');
        $data['status']=3;
        $data['delectInfo']=0;
        $count= Db::name("sendresume")->where($data)->count();
        if($count){
            echo $callback."($count)";
        }else{
            echo $callback.(0);
        }
    }

}